import base64
import pickle

from django.http import JsonResponse
from django.shortcuts import render
from django_redis import get_redis_connection
from requests import Response
from rest_framework.views import APIView

from carts.serializers import UserSkuCartSerializer, UserSkuCartListSerializer, DeleteCartSerializer
from goods.models import SKU
from utils.models import BaseModel


class Content(BaseModel):
    def get(self,request):
        #判断用户是否登陆
        try:
            user=request.user
        except:
            user=None
        if user and user.is_authenticated:
            #到redis购物车中查询sku列表
            redis_conn=get_redis_connection("cart")
            cart_selected_key = 'cart_selected_%s' % user.id
            cart_selected_set = redis_conn.smembers(cart_selected_key)
            count=cart_selected_set.count()
            return JsonResponse(data={"count":count})

